package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.GroupMapper;
import com.gxa.zhonglong.pojo.Group;
import com.gxa.zhonglong.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : 宸濯
 * Date: 2021/10/28 9:38
 * Description:
 * Version: V1.0
 */
@Service
public class GroupServiceImpl implements GroupService {

    @Autowired
    private GroupMapper groupMapper;

    @Override
    public List<Map<String, Object>> selectAllById(Long id) throws BusinessException {
        final List<Map<String, Object>> maps = groupMapper.selectAllById(id);
        if (maps.size()==0){
            throw new BusinessException(ExceptionCode.NODATA);
        }
        return maps;
    }

    @Override
    public void add(Group group) throws BusinessException {
        if (!groupMapper.add(group)) {
            throw new BusinessException(ExceptionCode.ADD_DEFEATED);
        }
    }

    @Override
    public void update(Group group) throws BusinessException {
        if (!groupMapper.update(group)) {
            throw new BusinessException(ExceptionCode.UPDATE_FALSE);
        }
    }

    @Override
    public void del(Long id) throws BusinessException {
        if (!groupMapper.del(id)) {
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }
    }
}
